package org.example.java8.defaultmethod;

/**
 * @author 夏焰波
 * @date 2020-07-15 1:31
 */
public class DefaultInAction3 {

    public static void main(String[] args) {
        C c = new C();
        c.hello();

    }

    private interface A {
        default void hello() {
            System.out.println("==A.hello==");
        }
    }

    //子类优先级较高
    private interface B extends A {
        @Override
        default void hello() {
            System.out.println("==B.hello==");
        }
    }

    //Classes always win.类的优先级最高
    private static class C implements B, A {
        @Override
        public void hello() {
            System.out.println("==C.hello==");
        }
    }

    private interface D {
        default void hello() {
            System.out.println("==D.hello==");
        }
    }

    //当继承的2个父类有相同的方法会冲突，此时需要重写自己的同名方法
    private static class E implements D, A {
        @Override
        public void hello() {
            A.super.hello();
            D.super.hello();
            System.out.println("==E.hello==");
        }
    }
}
